package com.example.demo;

import com.example.demo.entity.po.OrdersEntity;
import com.example.demo.service.OrdersAbstract;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @description: 乐观锁
 * @author: luojm
 * @create: 2018-05-14 19:25
 **/
public class OptimisticLocking extends BaseTest {
    @Autowired
    OrdersAbstract ordersAbstract;

    @Test
    public void selectAndUpdate1(){
        try {
            OrdersEntity ordersEntity = ordersAbstract.ordersMapper.selectOne(new OrdersEntity() {{
                setId("1");
            }});
            ordersEntity.setName("1234");
            int i = ordersAbstract.ordersMapper.updateByPrimaryKeySelective(ordersEntity);
            System.err.println(i);
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println(e);
        }
    }

    @Test
    public void selectAndUpdate2(){
        try {
            OrdersEntity ordersEntity = ordersAbstract.ordersMapper.selectOne(new OrdersEntity() {{
                setId("1");
            }});
            ordersEntity.setName("123456");
            int i = ordersAbstract.ordersMapper.updateByPrimaryKeySelective(ordersEntity);
            System.err.println(i);
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println(e);
        }
    }

}
